﻿using Furion;
using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Options;

namespace ST.Torch.WebApi.EntityFramework.Core;

[AppDbContext("DbConnectionString", DbProvider.SqlServer)]
public class DefaultDbContext : AppDbContext<DefaultDbContext>
{
    public DefaultDbContext(DbContextOptions<DefaultDbContext> options) : base(options)
    {
        //启用实体跟踪，默认 true;跟踪 AsTracking
        EnabledEntityStateTracked = false;

    }
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        //if (!optionsBuilder.IsConfigured)
        //{
            // 这里可以根据 Furion 的配置来获取连接字符串
            var connectionString = App.Configuration["ConnectionStrings:DbConnectionString"];
            optionsBuilder.UseSqlServer(connectionString);

            // 忽略 PendingModelChangesWarning 警告
            optionsBuilder.ConfigureWarnings(warnings => warnings.Ignore(RelationalEventId.PendingModelChangesWarning));
        //}
    }
}
